import UIKit

public class CodeBlockTheme {
    // MARK: - Properties
    public let backgroundColor: UIColor
    public let textColor: UIColor
    public let headerBackgroundColor: UIColor
    public let languageLabelColor: UIColor
    public let copyButtonTintColor: UIColor
    public let expandButtonColor: UIColor
    public let expandButtonTextColor: UIColor
    public let borderColor: UIColor?
    public let borderWidth: CGFloat
    public let cornerRadius: CGFloat
    public let font: UIFont
    public let languageLabelFont: UIFont
    public let expandButtonFont: UIFont
    public let containerInsets: UIEdgeInsets
    public let headerHeight: CGFloat
    public let headerInsets: UIEdgeInsets
    public let languageLabelInsets: UIEdgeInsets
    public let copyButtonSize: CGSize
    public let copyButtonInsets: UIEdgeInsets
    public let codeTextInsets: UIEdgeInsets
    public let expandButtonHeight: CGFloat
    public let expandButtonCornerRadius: CGFloat
    public let expandButtonInsets: UIEdgeInsets
    public let syntaxTheme: SyntaxTheme
    
    // MARK: - Initialization
    public init(
        backgroundColor: UIColor,
        textColor: UIColor,
        headerBackgroundColor: UIColor,
        languageLabelColor: UIColor,
        copyButtonTintColor: UIColor,
        expandButtonColor: UIColor,
        expandButtonTextColor: UIColor,
        borderColor: UIColor? = nil,
        borderWidth: CGFloat = 0,
        cornerRadius: CGFloat = 8,
        font: UIFont = .monospacedSystemFont(ofSize: 14, weight: .regular),
        languageLabelFont: UIFont = .systemFont(ofSize: 12, weight: .medium),
        expandButtonFont: UIFont = .systemFont(ofSize: 12, weight: .medium),
        containerInsets: UIEdgeInsets = .zero,
        headerHeight: CGFloat = 32,
        headerInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12),
        languageLabelInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 0),
        copyButtonSize: CGSize = CGSize(width: 24, height: 24),
        copyButtonInsets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 12),
        codeTextInsets: UIEdgeInsets = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12),
        expandButtonHeight: CGFloat = 28,
        expandButtonCornerRadius: CGFloat = 4,
        expandButtonInsets: UIEdgeInsets = .zero,
        syntaxTheme: SyntaxTheme
    ) {
        self.backgroundColor = backgroundColor
        self.textColor = textColor
        self.headerBackgroundColor = headerBackgroundColor
        self.languageLabelColor = languageLabelColor
        self.copyButtonTintColor = copyButtonTintColor
        self.expandButtonColor = expandButtonColor
        self.expandButtonTextColor = expandButtonTextColor
        self.borderColor = borderColor
        self.borderWidth = borderWidth
        self.cornerRadius = cornerRadius
        self.font = font
        self.languageLabelFont = languageLabelFont
        self.expandButtonFont = expandButtonFont
        self.containerInsets = containerInsets
        self.headerHeight = headerHeight
        self.headerInsets = headerInsets
        self.languageLabelInsets = languageLabelInsets
        self.copyButtonSize = copyButtonSize
        self.copyButtonInsets = copyButtonInsets
        self.codeTextInsets = codeTextInsets
        self.expandButtonHeight = expandButtonHeight
        self.expandButtonCornerRadius = expandButtonCornerRadius
        self.expandButtonInsets = expandButtonInsets
        self.syntaxTheme = syntaxTheme
    }
    
    // MARK: - Factory Methods
    public static func light() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: .secondarySystemBackground,
            textColor: .label,
            headerBackgroundColor: .systemGray6,
            languageLabelColor: .secondaryLabel,
            copyButtonTintColor: .secondaryLabel,
            expandButtonColor: .systemGray5,
            expandButtonTextColor: .label,
            syntaxTheme: SyntaxTheme.oneDark
        )
    }
    
    public static func dark() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: .secondarySystemBackground,
            textColor: .label,
            headerBackgroundColor: .systemGray6,
            languageLabelColor: .secondaryLabel,
            copyButtonTintColor: .secondaryLabel,
            expandButtonColor: .systemGray5,
            expandButtonTextColor: .label,
            syntaxTheme:SyntaxTheme.dracula
        )
    }
    
    public static func xcode() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: UIColor(red: 30/255, green: 30/255, blue: 30/255, alpha: 1),
            textColor: .white,
            headerBackgroundColor: UIColor(red: 40/255, green: 40/255, blue: 40/255, alpha: 1),
            languageLabelColor: .lightGray,
            copyButtonTintColor: .lightGray,
            expandButtonColor: UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 1),
            expandButtonTextColor: .white,
            syntaxTheme: SyntaxTheme.xcode
        )
    }
    
    public static func github() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: UIColor(red: 246/255, green: 248/255, blue: 250/255, alpha: 1),
            textColor: UIColor(red: 36/255, green: 41/255, blue: 46/255, alpha: 1),
            headerBackgroundColor: UIColor(red: 240/255, green: 242/255, blue: 244/255, alpha: 1),
            languageLabelColor: .gray,
            copyButtonTintColor: .gray,
            expandButtonColor: UIColor(red: 235/255, green: 237/255, blue: 239/255, alpha: 1),
            expandButtonTextColor: UIColor(red: 36/255, green: 41/255, blue: 46/255, alpha: 1),
            borderColor: UIColor(red: 208/255, green: 215/255, blue: 222/255, alpha: 1),
            borderWidth: 1,
            syntaxTheme: SyntaxTheme.github
        )
    }
    
    public static func dracula() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: UIColor(red: 40/255, green: 42/255, blue: 54/255, alpha: 1),
            textColor: UIColor(red: 248/255, green: 248/255, blue: 242/255, alpha: 1),
            headerBackgroundColor: UIColor(red: 68/255, green: 71/255, blue: 90/255, alpha: 1),
            languageLabelColor: UIColor(red: 98/255, green: 114/255, blue: 164/255, alpha: 1),
            copyButtonTintColor: UIColor(red: 98/255, green: 114/255, blue: 164/255, alpha: 1),
            expandButtonColor: UIColor(red: 68/255, green: 71/255, blue: 90/255, alpha: 1),
            expandButtonTextColor: UIColor(red: 248/255, green: 248/255, blue: 242/255, alpha: 1),
            syntaxTheme: SyntaxTheme.dracula
        )
    }
    
    public static func oneDark() -> CodeBlockTheme {
        return CodeBlockTheme(
            backgroundColor: UIColor(red: 40/255, green: 44/255, blue: 52/255, alpha: 1),
            textColor: UIColor(red: 171/255, green: 178/255, blue: 191/255, alpha: 1),
            headerBackgroundColor: UIColor(red: 33/255, green: 37/255, blue: 43/255, alpha: 1),
            languageLabelColor: UIColor(red: 92/255, green: 99/255, blue: 112/255, alpha: 1),
            copyButtonTintColor: UIColor(red: 92/255, green: 99/255, blue: 112/255, alpha: 1),
            expandButtonColor: UIColor(red: 33/255, green: 37/255, blue: 43/255, alpha: 1),
            expandButtonTextColor: UIColor(red: 171/255, green: 178/255, blue: 191/255, alpha: 1),
            syntaxTheme: SyntaxTheme.oneDark
        )
    }
} 
